<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="p" uri="/WEB-INF/pages.tld"%>  
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page import="com.taobao.api.domain.Trade" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
	String webContext = request.getContextPath();
%>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>同步到U9</title>
	<script language=JavaScript>  
   		function checkFlag(flag){
   			if(flag==0){
				document.getElementById("fapiao").disabled =true;
   	   	   	}else{
   	   	  		document.getElementById("fapiao").disabled =false;
   	   	   	}
   	   	}

		function sendTo() {
			var conf = window.confirm("确定同步该订单到U9？");
			if (conf) {
				var retVal = new Array();
				retVal[0] = getRadioValue("flag");
				retVal[1] = document.getElementById("fapiao").value;
				retVal[2] = document.getElementById("express").value;

				if(retVal[0]==1&&retVal[1]==""){
					alert("请输入发票抬头！");
					return;
				}
				if(retVal[2]==""){
					alert("请输入选择快递公司名称");
					return;
				}

				retVal[3] = ""; 
				var nameStrAll = getCheckboxValue("giftname");
				if(nameStrAll!=null){
					var nameStr = nameStrAll.split(",");
					var i;
					for(i=0;i<nameStr.length-1;i++){
						var num = document.getElementById(nameStr[i]).value;
						if(num==""){
							alert("所选赠品数量不能为空！");
							return;
						}
						if(isNaN(num)){
							alert("赠品数量需为数字！");
							return;
						}
						retVal[3] = retVal[3] + nameStr[i] + "," + num + ";";
					}
				}
				
				window.returnValue = retVal;
				window.close();
			}else{ 
				return;
			}
		}

		function getRadioValue(RadioName){
		    var obj;    
		    obj=document.getElementsByName(RadioName);
		    if(obj!=null){
		        var i;
		        for(i=0;i<obj.length;i++){
		            if(obj[i].checked){
		                return obj[i].value;            
		            }
		        }
		    }
		    return null;
		}
		function getCheckboxValue(radioName){   
		  	var obj = document.getElementsByName(radioName);    
				var objLen= obj.length;    
			  	var i;   
			  	var result="";   
				for (i = 0;i<objLen;i++){   
				    if (obj [i].checked==true) {   
				     result+=obj [i].value+",";    
			    }   
			  }   
		  return result;   
		} 
		function checkValue(id){
			var obj = document.getElementById(id+"checkbox");    
			    if (obj.checked==false) {   
			    	document.getElementById(id).value =""; 
			    	document.getElementById(id).disabled =true;
			    }   else{
			    	document.getElementById(id).disabled =false;
				}
		}
</script>  
</head>
<body>
	<table border="1" align="center" width="95%">
		<tr>
			<td align="right" style="font-weight:bolder">是否开发票:</td>
			<td><input name="flag" type="radio" checked value="0" onclick='checkFlag(0)'/>否 <input name="flag" type="radio" value="1" onclick='checkFlag(1)'/>是</td>
		</tr>
		<tr>
			<td align="right" style="font-weight:bolder">发票抬头:</td>
			<td><input id="fapiao" name="fapiao" type="text" width="200px" disabled size="50"/></td>
		</tr>
		<tr>
			<td align="right" style="font-weight:bolder">发货快递公司:</td>
			<td><input id="express" name="express" type="text" width="200px" size="50" value="韵达"/></td>
		</tr>
		<s:iterator value="giftList" id="tgift" status="index" >
			<s:if test="#index.first" >
				<tr>
					<td align="right" style="font-weight:bolder">赠品:</td>
					<td>&nbsp;</td>
				</tr>
			</s:if>
			<tr>
				<td align="right"><input type="checkbox" name="giftname" id="<s:property value ="#tgift.itemCodeU9"/>checkbox" value="<s:property value ="#tgift.itemCodeU9"/>" onclick="checkValue('<s:property value ="#tgift.itemCodeU9"/>')" />&nbsp;</td>
				<td><s:property value ="#tgift.name"/>
					数量：<input id="<s:property value ="#tgift.itemCodeU9"/>" disabled size="10" type="text"/></td>
			</tr>
		</s:iterator>
		<tr>
			<td colspan="2" align="center"><input type="button" value="提交" onclick="sendTo()"/></td>
		</tr>
	</table>
</body>
</html>